import Vue from 'vue'
import Router from 'vue-router'
import Fail from '@/components/Fail'


Vue.use(Router)

export default new Router({
  routes: [{
    path: '/',
    name: 'Login',
    component: resolve => require(['../components/page/Login.vue'], resolve), //懒加载
  }, {
    path: '/user',
    name: 'userindex',
    redirect: '/helloword', //定向重转发
    meta: {requireAuth: true,},// 添加该字段，表示进入这个路由是需要登录的
    component: resolve => require(['../components/common/Home.vue'], resolve),
    children: [{
      path: '/head',
      component: resolve => require(['../components/common/Homepaneluser.vue'], resolve),
      children: [{
        path: '/helloword',
        component: resolve => require(['../components/page/HelloWorld.vue'], resolve),
      },{
        path: '/BookSearchuser',
        component: resolve => require(['../components/page/BookSearch.vue'], resolve),
        meta: {requireAuth: true,},
      }, {
        path: '/myallborrowuser',
        component: resolve => require(['../components/page/Myallborrow.vue'], resolve),
        meta: {requireAuth: true,},
      }]
    }]
  }, {
    path: '/index',
    name: 'index',
    redirect: '/hello', //定向重转发

    component: resolve => require(['../components/common/Home.vue'], resolve),
    children: [{
      path: '/head',
      component: resolve => require(['../components/common/Homepanel.vue'], resolve),
      children: [{
        path: '/hello',
        component: resolve => require(['../components/page/HelloWorld.vue'], resolve),
        meta: {requireAuth: true,},
      },{
        path: '/alluser',
        component: resolve => require(['../components/page/AllUser.vue'], resolve),
        meta: {requireAuth: true,},
      },{
        path: '/allbook',
        component: resolve => require(['../components/page/AllBook.vue'], resolve),
        meta: {requireAuth: true,},
      }, {
        path: '/BookSearch',
        component: resolve => require(['../components/page/BookSearch.vue'], resolve),
        meta: {requireAuth: true,},
      }, {
        path: '/myallborrow',
        component: resolve => require(['../components/page/Myallborrow.vue'], resolve),
        meta: {requireAuth: true,},
      }, {
        path: '/BookSearch',
        component: resolve => require(['../components/page/BookSearch.vue'], resolve),
        meta: {requireAuth: true,},
      }]
    }]
  }, {
    path: '/Fail',
    name: 'Fail',
    component: Fail
  }, {
    path: '/Codetest',
    name: 'Codetest',
    component: resolve => require(['../components/page/Codetest.vue'], resolve),
  }]
})

function newFunction() {
  return '/search';
}
